package servlet;/*
    @ClassName:     FileUploadServer
    @Author:        YangXu
    @Need:          
    @Date:          2022/3/28
    @Time:          19:59
    */

//

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/uploadd")
@MultipartConfig
public class FileUploadServer extends HttpServlet {
    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String savePath=req.getServletContext().getRealPath("./uploadFile");

        File file=new File(savePath);

        if(!file.exists()){
            file.mkdirs();
        }

        Part part=req.getPart("upfile");
        String fileName = "feature1.jpg";
        File f=new File(savePath+File.separator+fileName);
        if (f.exists()){
            f.delete();
        }
        part.write(savePath+File.separator+fileName);

        PrintWriter out = resp.getWriter();
        System.out.println("上传成功");
        out.println("上传成功");
        out.flush();
        out.close();

    }
}


/*

 */